//
//  MCBasicViewController+TableViewSet.m
//  MCPublicModule
//
//  Created by Mirko on 16/3/4.
//  Copyright © 2016年 Mirko. All rights reserved.
//

#import "MCBasicViewController+TableViewSet.h"

const static NSInteger kAllCellNoSpace = -1;

@implementation MCBasicViewController(TableViewSet)

-(void) setTableViewCellLineNoSpace
{
    self.cellLineNoSpace = YES;
    if ([self.mcTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.mcTableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([self.mcTableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.mcTableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.cellLineNoSpace) {
        NSInteger idx = [self noSpaceLineIndex];
        if (idx == kAllCellNoSpace) {
            if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
                [cell setSeparatorInset:UIEdgeInsetsZero];
            }
            if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                [cell setLayoutMargins:UIEdgeInsetsZero];
            }
        }
        else
        {
            if (idx == indexPath.row) {
                if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
                    [cell setSeparatorInset:UIEdgeInsetsZero];
                }
                if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                    [cell setLayoutMargins:UIEdgeInsetsZero];
                }
            }
        }

    }
}

-(NSInteger) noSpaceLineIndex
{
    return kAllCellNoSpace;
}

@end
